import axios from '@/api'
import { IField, IPlant, IYKTAccount } from './famer'

export interface IGetLargeMemberList {
  request: Partial<ILargeMember>
  response: Array<ILargeMember>
}

export interface ILargeMember {
  big_mb_id: string
  s_a_id: string
  s_a_nam: string
  s_a_nam_all: string
  big_mb_nam: string
  big_mb_type: string
  big_mb_law_id: string
  big_mb_addr: string
  big_mb_bank_id: string
  big_mb_bank_code: string
}

export interface ILargeMemberDetail extends ILargeMember, ICheck {
  plant: string
  field_had: string
  field_had_water: string
  field_had_dry: string
  field_gave: string
  field_gave_waiter: string
  field_gave_dry: string
  material: string
  machine: string
}

export interface ICheck {
  apl_time: string
  big_mb_ck: string
  big_mb_ck_u: string
  big_mb_time: string
  big_mb_ck1: string
  big_mb_ck_u1: string
  big_mb_time1: string
  big_mb_ck2: string
  big_mb_ck_u2: string
  big_mb_time2: string
  big_mb_ck3: string
  big_mb_ck_u3: string
  big_mb_time3: string
}

export interface ILargeField extends IField {
  big_mb_id: string;
  field_id2: string;
}
export interface ILargePlant extends IPlant {
  big_mb_id: string
}

export interface IGetLargeMemberFieldDetail {
  request: Pick<ILargeField, 'big_mb_id' | 's_a_id' | 'field_from'>
  response: ILargeMemberDetail[]
}

// 转入
export interface IIntoField {
  field_id: string
  member_id: string
  member_nam: string
  s_a_nam_all: string
  field_size: number
  field_type: string
}
export interface IGetIntoField {
  request: Partial<Pick<IIntoField, 'field_id' | 'member_id' | 'member_nam'>> & Api.PageOptions
  response: IIntoField[]
}


class LargeMemberServices {
  constructor() {}

  /**
   * 获取种粮大户列表
   *
   * @param {IGetLargeMemberList['request']} data
   * @returns
   * @memberof UserServices
   */
  getLargeMemberList(data: IGetLargeMemberList['request']) {
    return axios.post<
      unknown,
      Api.ResponseListOptions<IGetLargeMemberList['response']>
    >('/btbusiness/big-member/get-list', data)
  }

  /**
   * 编辑/添加种粮大户
   *
   * @param {IAdmin} data
   * @returns
   * @memberof UserServices
   */
  updateLargeMember(data: ILargeMember) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/edit',
      data
    )
  }

  /**
   * 删除种粮大户
   *
   * @param {(Pick<IMember, 'member_id' | 's_a_id'>)} data
   * @returns
   * @memberof LargeMemberServices
   */
  deleteLargeMember(
    data: Pick<ILargeMember, 'big_mb_id' | 's_a_id'> & { all: string }
  ) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/del',
      {
        ...data,
        all: data.all || 1,
      }
    )
  }

  /**
   * 获取种粮大户详细信息
   *
   * @param {Partial<ILargeMember>} data
   * @returns
   * @memberof LargeMemberServices
   */
  getLargeMemberDetail(data: Partial<ILargeMember>) {
    return axios.post<unknown, Api.ResponseListOptions<ILargeMemberDetail[]>>(
      '/btbusiness/big-member/get-detail-list',
      data
    )
  }

  /**
   * 获取种粮大户耕地信息
   *
   * @param {IGetLargeMemberFieldDetail['request']} data
   * @returns
   * @memberof LargeMemberServices
   */
  getLargeMemberFields(data: IGetLargeMemberFieldDetail['request']) {
    return axios.post<
      unknown,
      Api.ResponseListOptions<IGetLargeMemberFieldDetail['response']>
    >('/btbusiness/big-member/get-field', data)
  }

  /**
   * 更新种粮大户耕地信息
   *
   * @param {Partial<ILargeField>} data
   * @returns
   * @memberof LargeMemberServices
   */
  updateLargeMemberField(data: Partial<ILargeField>) {
    return axios.post<unknown, Api.ResponseListOptions>(
      '/btbusiness/big-member/edit-field',
      data
    )
  }

  /**
   *  删除大户耕地信息
   *
   * @param {Partial<IField>} data
   * @returns
   * @memberof FamerServices
   */
  public deleteLargeMemberField(data: Partial<IField>) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/del-field',
      data
    )
  }

  /**
   * 获取种粮大户耕地信息
   *
   * @param { big_mb_id: string } data
   * @returns
   * @memberof LargeMemberServices
   */
  getLargeMemberPlants(data: { big_mb_id: string; s_a_id: string }) {
    return axios.post<unknown, Api.ResponseListOptions<ILargePlant[]>>(
      '/btbusiness/big-member/get-plant',
      data
    )
  }

  /**
   * 更新种粮大户耕地信息
   *
   * @param {Partial<ILargeField>} data
   * @returns
   * @memberof LargeMemberServices
   */
  updateLargeMemberPlant(data: Partial<ILargeField>) {
    return axios.post<unknown, Api.ResponseListOptions>(
      '/btbusiness/big-member/edit-plant',
      data
    )
  }

  /**
   * 获取种粮大户农机信息
   *
   * @param { big_mb_id: string } data
   * @returns
   * @memberof LargeMemberServices
   */
  getLargeMemberMachines(data: { big_mb_id: string; s_a_id: string }) {
    return axios.post<unknown, Api.ResponseListOptions<ILargePlant[]>>(
      '/btbusiness/big-member/get-machine',
      data
    )
  }

  /**
   * 更新种粮大户农机信息
   *
   * @param {Partial<ILargeField>} data
   * @returns
   * @memberof LargeMemberServices
   */
  updateLargeMemberMachines(data: Partial<ILargeField>) {
    return axios.post<unknown, Api.ResponseListOptions>(
      '/btbusiness/big-member/edit-machine',
      data
    )
  }

  /**
   * 大户审核
   *
   * @param {(Partial<ICheck> & Pick<ILargeMember, 'big_mb_id' | 's_a_id'>)} data
   * @returns
   * @memberof LargeMemberServices
   */
  checkLargeMember(
    data: Partial<ICheck> & Pick<ILargeMember, 'big_mb_id' | 's_a_id'>
  ) {
    return axios.post<unknown, Api.ResponseListOptions>(
      '/btbusiness/big-member/check',
      data
    )
  }

  /**
   * 批量审核
   *
   * @param {(Partial<ICheck> & Pick<ILargeMember, 's_a_id'>)} data
   * @returns
   * @memberof LargeMemberServices
   */
  BatchVerify(
    data: Partial<ICheck> & Pick<ILargeMember, 's_a_id'>
  ) {
    return axios.post<unknown, Api.ResponseListOptions>(
      '/btbusiness/big-member/area-check',
      data
    )
  }

  /**
   * 获取种粮大户农资信息
   *
   * @param { big_mb_id: string } data
   * @returns
   * @memberof LargeMemberServices
   */
  getLargeMemberMaterial(data: { big_mb_id: string; s_a_id: string }) {
    return axios.post<unknown, Api.ResponseListOptions<ILargePlant[]>>(
      '/btbusiness/big-member/get-material',
      data
    )
  }

  /**
   * 更新种粮大户农资信息
   *
   * @param {Partial<ILargeField>} data
   * @returns
   * @memberof LargeMemberServices
   */
  updateLargeMemberMaterial(data: Partial<ILargeField>) {
    return axios.post<unknown, Api.ResponseListOptions>(
      '/btbusiness/big-member/edit-material',
      data
    )
  }

  /**
   * 获取大户预览信息
   *
   * @param {{ big_mb_id: string, s_a_id: string; }} data
   * @returns
   * @memberof LargeMemberServices
   */
  getLargeMemberPreview(data: { big_mb_id: string; s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/get-member-detail',
      data
    )
  }

  /**
   * 批量插入大户数据
   *
   * @param {ILargeMemberDetail[]} data
   * @returns
   * @memberof LargeMemberServices
   */
  batchInsert(params: {data: ILargeMemberDetail[], file_nam: string}) {
    return axios.post<Api.ResponseOptions & { msg: string[] }>(
      '/btbusiness/big-member/batch-insert',
      params,
      {
        customHandler: true
      }
    )
  }

  /**
   * 获取可转入地列表
   *
   * @param {IGetIntoField['request']} data
   * @returns
   * @memberof LargeMemberServices
   */
  getIntoFieldsList(data: IGetIntoField['request']) {
    return axios.post<unknown, Api.ResponseListOptions<IGetIntoField['response']>>(
      '/btbusiness/big-member/get-add-field-list',
      data
    )
  }

  /**
   * 确认转入
   *
   * @param {(Pick<IIntoField, 'field_size' | 'field_id' | 'member_id'> & { big_member_id: string, type: string })} data
   * @returns
   * @memberof LargeMemberServices
   */
  updateIntoField(data: Pick<IIntoField, 'field_size' | 'field_id' | 'member_id'> & { big_member_id: string, type: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/edit-change-field',
      data
    )
  }

  /**
   * 导出大户execl表
   *
   * @param {(Partial<ILargeMember> & Api.PageOptions & { keys: string[] })} data
   * @returns
   * @memberof LargeMemberServices
   */
  exportExecl(data: Partial<ILargeMember> & Api.PageOptions & { keys: string[] }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/export-big-member',
      data,
      {
        customHandler: true,
        responseType: 'blob'
      }
    )
  }

  /**
   * 导出分户明细
   *
   * @param { big_mb_id: string } data
   * @returns
   * @memberof LargeMemberServices
   */
  exportFieldExecl(data: { big_mb_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/export-field',
      data,
      {
        customHandler: true,
        responseType: 'blob'
      }
    )
  }

  /**
   * 导入一卡通账号
   *
   * @param {{ s_a_id: string, file_nam?: string; data: IYKTAccount[] }} data
   * @returns
   * @memberof LargeMemberServices
   */
  importFieldExecl(data: { s_a_id: string, file_nam?: string; data: IYKTAccount[] }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/import-account',
      data,
      {
        customHandler: true
      }
    )
  }

  /**
   * 同步上一年数据到本年
   *
   * @param {{s_a_id: string }} data
   * @returns
   * @memberof FamerServices
   */
   syncLastYearData(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/export-last-year',
      data
    )
  }

  /**
   * 批量删除未补贴的大户
   *
   * @param {{ s_a_id: string }} data
   * @returns
   * @memberof LargeMemberServices
   */
  batchDelsUnUsed(data: { s_a_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/del-area-member',
      data
    )
  }

  /**
   * 获取大户申报图片
   *
   * @param {{ big_mb_id: string }} data
   * @returns
   * @memberof LargeMemberServices
   */
  getImages(data: { big_mb_id: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/get-img',
      data
    )
  }

  /**
   * 获取大户申报图片
   *
   * @param {{ big_mb_id: string }} data
   * @returns
   * @memberof LargeMemberServices
   */
  updateImages(data: { big_mb_id: string, big_mb_img: string }) {
    return axios.post<unknown, Api.ResponseOptions>(
      '/btbusiness/big-member/upload-img',
      data
    )
  }
}

export const largeMemberServices = new LargeMemberServices()

export default LargeMemberServices
